<template>
    <div>
        <van-field label="添加名称" placeholder="请输入名称" v-model="form.name"/>
        <van-field label="添加价格" placeholder="请输入价格" v-model="form.price"/>
        <br>
        图片上传:<van-uploader :after-read="afterRead"/>
    </div>
</template>

<script>
    export default {
        data(){
            return{
                form:{},
                pic:'http://localhost:5000/static/upload/',
            }
        },
        methods:{
            afterRead(file){
                //只要是上传文件就需要声明formdata
                let data= new FormData()
                //将afterRead里的文件放到data里
                data.append('file',file.file)
                this.$axios.post('upload',data)
                .then(res=>{
                    this.pic="http://localhost:5000/static/upload/"+res.data.pic
                })
            },
        },
        mounted(){},
    }
</script>

<style scoped>

</style>